<template>
  <div>
用户名：<input type="text" v-model.trim="userInfo.username"><br/>
密码：<input type="text" v-model.trim="userInfo.pwd"><br/>
性别：<input type="radio" :value="0" v-model="userInfo.gendar">♂
     <input type="radio" :value="1" v-model="userInfo.gendar">♀<br/>
手机号：<input type="number" v-model="userInfo.phone"><br/>
头像：<input type="url" v-model="userInfo.imgurl"><br/>
 <button @click="goReg">注册</button><br/>
 <button @click="$router.push('/login')">登录</button>
  </div>
</template>

<script>
import request from '../request/index.js'
export default {
  data() {
    return {
        userInfo:{
               username: "",
               gendar: 0,
               phone: "",
               pwd: "",
               imgurl: "", 
        }
    };
  },
 
  created() {},
  methods: {
       async goReg(){
            const {data:res}=await request({url:"/users/register",method:"post",data:{data:JSON.stringify(this.userInfo)}})
            if(res.status!=0)return alert('注册失败')
            if(res.message=="账号已存在")return alert('账号已存在')
            alert('注册成功!请登录。。。。')
       }
  },
};
</script>
<style scoped>
</style>